#include <gtest/gtest.h>
#include <mockcpp/mockcpp.hpp>

int func(int a)
{
    return 0;
}

int mock_func(int a)
{
    return 6;
}

TEST(sample, func_test)
{
     // 对一个函数重复mock，需要用reset
    GlobalMockObject::reset();
    MOCKER(func)
        .expects(atMost(3)) // 指定所有测试用例能调用的次数
        // .expects(exactly(3)) // 如果不reset，指定调用的具体次数可能不起作用
        .with(eq(3))
        .will(returnValue(2))
        .then(returnValue(3))
        .then(invoke(mock_func));

    EXPECT_EQ(2, func(3));
    EXPECT_EQ(3, func(3));
    EXPECT_EQ(6, func(3));
    // EXPECT_EQ(6, func(3));
    GlobalMockObject::verify();
}

TEST(sample, func_test_invoke_mock)
{
    GlobalMockObject::reset();
    MOCKER(func)
        .expects(once())
        .will(invoke(mock_func))
        .then(returnValue(8))
        .then(invoke(mock_func));

    // EXPECT_EQ(6, func(3));
    EXPECT_EQ(8, func(3));
    GlobalMockObject::verify();
}

int main(int argc, char *argv[])
{
    ::testing::InitGoogleTest(&argc, argv);
    return RUN_ALL_TESTS();
}
